package com.ruoyi.project.knowledge.InvalidBooks.controller;

import java.util.List;

import com.ruoyi.project.knowledge.damage.domain.KnowledgeFractureDamageInfo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.knowledge.InvalidBooks.domain.KnowledgeFailedBooksInfo;
import com.ruoyi.project.knowledge.InvalidBooks.service.IKnowledgeFailedBooksInfoService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 失效书籍信息Controller
 * 
 * @author ruoyi
 * @date 2024-04-27
 */
@Controller
@RequestMapping("/knowledge/InvalidBooks")
public class KnowledgeFailedBooksInfoController extends BaseController
{
    private String prefix = "knowledge/InvalidBooks";

    @Autowired
    private IKnowledgeFailedBooksInfoService knowledgeFailedBooksInfoService;

    @RequiresPermissions("knowledge:InvalidBooks:view")
    @GetMapping()
    public String InvalidBooks()
    {
        return prefix + "/InvalidBooks";
    }

    /**
     * 查询失效书籍信息列表
     */
    @RequiresPermissions("knowledge:InvalidBooks:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(KnowledgeFailedBooksInfo knowledgeFailedBooksInfo)
    {
        startPage();
        List<KnowledgeFailedBooksInfo> list = knowledgeFailedBooksInfoService.selectKnowledgeFailedBooksInfoList(knowledgeFailedBooksInfo);
        return getDataTable(list);
    }

    /**
     * 导出失效书籍信息列表
     */
    @RequiresPermissions("knowledge:InvalidBooks:export")
    @Log(title = "失效书籍信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(KnowledgeFailedBooksInfo knowledgeFailedBooksInfo)
    {
        List<KnowledgeFailedBooksInfo> list = knowledgeFailedBooksInfoService.selectKnowledgeFailedBooksInfoList(knowledgeFailedBooksInfo);
        ExcelUtil<KnowledgeFailedBooksInfo> util = new ExcelUtil<KnowledgeFailedBooksInfo>(KnowledgeFailedBooksInfo.class);
        return util.exportExcel(list, "失效书籍信息数据");
    }

    /**
     * 新增失效书籍信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存失效书籍信息
     */
    @RequiresPermissions("knowledge:InvalidBooks:add")
    @Log(title = "失效书籍信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(KnowledgeFailedBooksInfo knowledgeFailedBooksInfo)
    {
        return toAjax(knowledgeFailedBooksInfoService.insertKnowledgeFailedBooksInfo(knowledgeFailedBooksInfo));
    }

    /**
     * 失效书籍信息
     */
    @RequiresPermissions("knowledge:InvalidBooks:detail")
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") Long id, ModelMap mmap)
    {
        KnowledgeFailedBooksInfo knowledgeFailedBooksInfo = knowledgeFailedBooksInfoService.selectKnowledgeFailedBooksInfoById(id);
        mmap.put("knowledgeFailedBooksInfo", knowledgeFailedBooksInfo);

        return prefix + "/detail";
    }

    /**
     * 修改失效书籍信息
     */
    @RequiresPermissions("knowledge:InvalidBooks:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        KnowledgeFailedBooksInfo knowledgeFailedBooksInfo = knowledgeFailedBooksInfoService.selectKnowledgeFailedBooksInfoById(id);
        mmap.put("knowledgeFailedBooksInfo", knowledgeFailedBooksInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存失效书籍信息
     */
    @RequiresPermissions("knowledge:InvalidBooks:edit")
    @Log(title = "失效书籍信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(KnowledgeFailedBooksInfo knowledgeFailedBooksInfo)
    {
        return toAjax(knowledgeFailedBooksInfoService.updateKnowledgeFailedBooksInfo(knowledgeFailedBooksInfo));
    }

    /**
     * 删除失效书籍信息
     */
    @RequiresPermissions("knowledge:InvalidBooks:remove")
    @Log(title = "失效书籍信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(knowledgeFailedBooksInfoService.deleteKnowledgeFailedBooksInfoByIds(ids));
    }
}
